var express = require('express');
const { uploadFile } = require("tools-factory-tang");
const { update, deleteImg ,updatePoster,delPoster} = require("../api/movies");


// 路由
var router = express.Router();

// 处理上传 成功后拿到的东西
router.post("/upload", async function (req, res, next) {
    const { data } = await uploadFile(req, { fileType: "movies" });//fileType分类
    const result = await update(data);
    res.send(result)
});

// 海报
router.post("/uploadPoster", async function (req, res, next) {
    const { data } = await uploadFile(req, { fileType: "moviesPoster" });//fileType分类 
    const result = await updatePoster(data);
    console.log(result);
    res.send(result);
});

//删除 imgs 对应值 
router.delete("/:_id/movies/:url", async function (req, res, next) {
    const { _id, url } = req.params;
    const result = await deleteImg({ _id, url })
    res.send(result);
});

//删除海报
router.delete("/:_id/moviesPoster/:url", async function (req, res, next) {
    const { _id, url } = req.params;
    const result = await delPoster({ _id, url })
    res.send(result);
});

module.exports = router;
